<?php namespace App\Controllers\Admin;
/*
|=====================================================================
| Admin Controller
|=====================================================================
|
| This is the admin main class. Here is where we verify if the user is logged 
| and which is the information he can CRUD.
|
*/
class AdminController extends \BaseController {

    // Set up the basic layout.
    protected $layout = 'admin.index';
    protected $userID = 0;
   
    public function __construct() {
     
        // add some security to the post actions
        $this->beforeFilter('csrf', array('on'=>'post'));
        // if the user is not logged in he just enter to the login form and post information to login.    
        $this->beforeFilter('administrationauth', array('except'=>array('getLogin', 'postLogin')));        
        
        $this->checkSuperUser();        
    }
    
    // ---------------------------------------------------------------------        
    // checkSuperUser, return if the current user is superuser.
    // return boolean
    // ---------------------------------------------------------------------        
    public function checkSuperUser() {
        if(\Sentry::check()) {
            $user = \Sentry::getUser();
            $this->superuser = $user->isSuperUser();
            $this->userID = $user->id;
        }
        else $this->superuser = false;
        \View::share('superuser', $this->superuser);
    }
}
